home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
pascal
/
itsybit.exe
/
ITSYBITS.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1993-01-12
|
28KB
|
902 lines
unit ItsyBits;
{
Unit: ITSYBITS.PAS
Description: Provides support for windows with small captions.
Version: 1.0
Creation Date: January 7, 1993
Modification Date: January 12, 1993
Operating System: MS-DOS 3.x and Windows 3.1
Hardware Required: Windows-capable computer system
Programming System: Borland Pascal for Windows 7.0
BPW Translation by: Craig Boyd
Original Author: Charles E. Kindel, Jr. (9/27/91).
About This Unit
This is a BPW translation of ITSYBITS.C, which can be found in
ITSBITS.ZIP in Lib 5 of the WINSDK forum on CompuServe. Consult
ITSYBITS.DOC (included in ITSBITS.ZIP) for more information on using
ItsyBitsy windows. Note that there is another version of ITSBITS.ZIP
in Lib 1 of WINSDK that has a later upload date. I haven't looked at
it, so I don't know what, if anything, is different from the version
in Lib 5. Note also that forum libraries can be rearranged at a
moment's notice, so please don't blame me if ITSBITS.ZIP turns up
missing!
The only thing I've added to ITSYBITS.PAS that's not in ITSYBITS.C is
the TItsyBitsWindow object declaration, which let's you use ItsyBits
windows in OWL-based programs. IBTEST.PAS is a sample program
showing how to use windows derived from TIstyBitsWindow.
The following comments are from the original author:
ItsyBitsy is a support module that allows you to create windows that
look and act very much like a popup window with a system menu and
caption bar, except everything is scaled to about 2/3 scale.
For documentation on how to use ItsyBits, read the document
ITSYBITS.RTF, which is in rich text format.
Little known fact: ExtTextOut() is the fastest way to draw a filled
rectangle in Windows (if you don't want dithered colors or borders).
Unfortunately there is a bug in the Windows 3.0 8514 driver in using
ExtTextOut() to a memory DC. If you are drawing to an off screen
bitmap, then blitting that bitmap to the display, do not define
USE_EXTTEXTOUT below.
The macro (DRAWFASTRECT) draws a filled rectangle with no border and a
solid color. It uses the current background color as the fill color.
Update History
update ver description (author)
------- --- -----------
9301.07 0.0 Work begun on translating C source code. (CSB)
9301.08 1.0 First working version. (CSB)
9301.12 1.0 Updated comments. (CSB)
}
{$define USE_EXTTEXTOUT}
{-- Interface Section ---------------------------------------------------}
{$R-,S-}
interface
uses
WinTypes,
OWindows;
const
ibs_HorzCaption = $00004000;
ibs_VertCaption = $00008000;
function ibDefWindowProc(HWin : hwnd;
wMsg,
wParam : word;
lParam : longint) : longint;
{
This function should be called instead of DefWindowProc() for windows
that want to have itsybitsy captions.
}
procedure ibAdjustWindowRect( HWin : hwnd;
var lprc : TRect);
{
Does the same thing as the USER function AdjustWindowRect(), but knows
about itsybitsy windows. AdjustWindowRect() is bogus it appears.
}
type
PItsyBitsWindow = ^TItsyBitsWindow;
TItsyBitsWindow = object(TWindow)
constructor Init(aParent: PWindowsObject; aTitle: PChar; ibs_Style : longint);
procedure DefWndProc(var Msg : TMessage); virtual;
function GetClassName : pchar; virtual;
end;
{-- Implementation Section ----------------------------------------------}
implementation
uses
WinProcs,
Win31;
const
{ BBGGRR}
RGBLtGray = $00C0C0C0;
RGBGray = $00808080;
RGBBlack = $00000000;
RGBWhite = $00FFFFFF;
var
gcCaption : word;
fWin31 : bool;
{-- TItsyBits Methods ---------------------------------------------------}
constructor TItsyBitsWindow.Init;
{
Overrides TWindow.Init. Attr.Style is set to (ws_ThickFrame or
ws_Border or ws_Popup or ws_SysMenu or ws_Visible). Attr.Style also
includes the ibs_Style bit, which determines what type of caption this
ItsyBits window will have. The allowable values are:
ibs_Style Meaning
----- -------
ibs_VertCaption Give the window a vertical caption.
ibs_HorzCaption Give the window a horizontal caption.
If an invalid ibs_Style bit is specified, the default will be
ibs_HorzCaption.
}
begin
inherited Init(aParent,aTitle);
if (ibs_Style <> ibs_HorzCaption) and (ibs_Style <> ibs_VertCaption) then
ibs_Style := ibs_HorzCaption;
with Attr do begin
Style :=
ibs_Style or
ws_ThickFrame or
ws_Border or
ws_Popup or
ws_SysMenu or
ws_Visible;
end;
end { TItsyBitsWindow.Init };
procedure TItsyBitsWindow.DefWndProc;
{
Overrides TWindow.DefWndProc. Calls ibDefWindowProc for certain
messages. Other messages are passed on to DefWndProc.
If you add any more message handling capabilities to ibDefWindowProc,
you must also update this method.
}
begin
case Msg.Message of
wm_SysChar,
wm_SysKeyDown,
wm_SysKeyUp,
wm_KeyDown,
wm_KeyUp,
wm_GetMinMaxInfo,
wm_Command,
wm_NCCreate,
wm_NCCalcSize,
wm_NCHitTest,
wm_NCLButtonDblClk,
wm_NCLButtonDown,
wm_NCActivate,
wm_NCPaint : begin
with Msg do
Result := ibDefWindowProc(Receiver,Message,wParam,lParam);
end
else
inherited DefWndProc(Msg);
end;
end { TItsyBitsWindow.DefWndProc };
function TItsyBitsWindow.GetClassName;
{
Returns a class name of 'ItsyWnd';
}
begin
GetClassName := 'ItsyWnd';
end { TItsyBitsWindow.GetClassName };
{-- Local Functions -----------------------------------------------------}
function CaptionXY : integer;
begin
CaptionXY := GetSystemMetrics(sm_CYCaption) div 2 + 4;
end { CaptionXY };
function GetStyle(HWin : hwnd) : word;
begin
GetStyle := LoWord(GetWindowLong(HWin,gwl_Style));
end { GetStyle };
function HasCaption(HWin : hwnd) : boolean;
begin
HasCaption := ((GetStyle(HWin) and ibs_VertCaption) <> 0) or
((GetStyle(HWin) and ibs_HorzCaption) <> 0);
end { HasCaption };
function TestWinStyle(HWin : hwnd;
dwStyleBit : longint) : bool;
begin
TestWinStyle := (GetWindowLong(HWin,gwl_Style) and dwStyleBit) <> 0;
end { TestWinStyle };
{$ifdef USE_EXTTEXTOUT}
procedure DrawFastRect( DC : hdc;
var lprc : TRect);
begin
ExtTextOut(DC,0,0,eto_Opaque,@lprc,nil,0,nil);
end { DrawFastRect };
{$else}
procedure DrawFastRect( DC : hdc;
var lprc : TRect);
var
hbr : HBrush;
begin
hbr := CreateSolidBrush(GetBkColor(DC));
hbr := SelectObject(DC,hbr);
PatBlt(DC,lprc.left,lprc.top,lprc.right - lprc.left,lprc.bottom - lprc.top,PatCopy);
hbr := SelectObject(DC,hbr);
DeleteObject(hbr);
end;
{$endif}
function ibGetCaptionRect( HWin : hwnd;
var lprc : TRect) : bool;
{
Calcluales the rectangle of the mini-caption in screen coords.
}
begin
if not HasCaption(HWin) then begin
SetRectEmpty(lprc);
ibGetCaptionRect := false;
exit;
end;
GetWindowRect(HWin,lprc);
{
The window might have other non-client components like borders.
}
if TestWinStyle(HWin,ws_ThickFrame) then
begin
inc(lprc.left,GetSystemMetrics(sm_CXFrame));
inc(lprc.top,GetSystemMetrics(sm_CYFrame));
dec(lprc.right,GetSystemMetrics(sm_CXFrame));
dec(lprc.bottom,GetSystemMetrics(sm_CYFrame));
end
else
if TestWinStyle(HWin,ws_Border) then begin
inc(lprc.left,GetSystemMetrics(sm_CXBorder));
inc(lprc.top,GetSystemMetrics(sm_CYBorder));
dec(lprc.right,GetSystemMetrics(sm_CXBorder));
d